<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script button="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" id="form" method="post"
                              action="<?php echo site_url(X_URL . 'Category/update'); ?>">
                            <input name="id" type="hidden" value="<?php if (isset($category)) {
                                echo $category["id"];
                            } ?>">
                            <?php echo csrf_hidden(); ?>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 分类名称 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="category_name" id="category_name" placeholder="名称"
                                           class="col-xs-10 col-sm-5" value="<?php if (isset($category)) {
                                        echo $category["category_name"];
                                    } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    图片上传 </label>
                                <div class="col-sm-9">
                                    <input id="kv-explorer" class="col-xs-10 col-sm-5" name="file" type="file"
                                           accept="image/*" multiple>
                                </div>
                            </div>
                            <input type="hidden" id="cover" name="cover"
                                   value="<?php if (!empty($article['cover'])) {
                                       echo $article['cover'];
                                   } ?>">
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 排序 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="order" id="order" placeholder="排序"
                                           class="col-xs-10 col-sm-5" value="<?php if (isset($category)) {
                                        echo $category["order"];
                                    } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer'); ?>
</div>


<?php $this->load->view('common/footerjs'); ?>
<!-- inline scripts related to this page -->
<script button="text/javascript">
    $(function () {
        $(".btn-info.submit").click(function () {
            var category_name = $("#category_name").val();
            if (category_name == "") {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "分类名称必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            $("#form").submit();
        });
    });
    var picpath = <?php echo $pic_path;?>;
    var piccon = <?php echo $pic_con;?>;
    $(document).ready(function () {
        $("#kv-explorer").fileinput({
            language: 'zh',
            uploadAsync: false, //设置上传同步异步 此为同步
            showRemove:false,
            showCaption:false,
            dropZoneEnabled: false,
            'theme': 'explorer-fa',
            'uploadUrl': baseurl + 'index.php/Upload/do_upload?type=category',
            overwriteInitial: false,
            initialPreviewAsData: true,
            initialPreviewFileType: 'image',
            initialPreview: picpath, //要显示的图片的路径
            initialPreviewConfig: piccon
        });
        $("#kv-explorer").on("filebatchuploadsuccess", function (event, data) {
            var rst = data.response;
            if (rst.status == 2) {
                layer.msg(rst.msg);
            }
            var img = rst.url;
            $("#cover").val(img);
            // alert(rst);
        });


    });
    $(".OrderTypeCheck").click(function () {
        var val = $(this).val();
        if (val == 2) {
            $(".OrderTypeValue").hide();
        } else {
            $(".OrderTypeValue").show();
        }
    });
</script>
</body>
</html>
